<!DOCTYPE HTML>
<html>
<head>
    <title>增加</title>
    <link rel="stylesheet" href="/stylesheets/style.css">
    <script src="/scripts/jquery.min.js"></script>
    <script src="/scripts/boot.js" type="text/javascript"></script>
    <link rel="stylesheet" href="/scripts/miniui/themes/default/miniui.css">
    <link rel="stylesheet" href="/scripts/miniui/themes/icons.css">
    <link rel="stylesheet" href="/scripts/miniui/themes/bootstrap/skin.css">
    <link rel="stylesheet" href="/editor/common.css">
    <script src="/scripts/miniui/miniui.js"></script>
</head>
<body>
<div id="form1" style="padding-left: 60px">
    <span style="width:60px;display:inline-block;">名称：</span>
    <input id="btnEdit1" class="mini-buttonedit" onbuttonclick="onButtonEdit" name="a" textName="b"/>
    <span style="width:60px;display:inline-block;">价格：</span>
    <input id="price" name="price" class="mini-textbox" required="true" type="number" style="width:155px;" />
    <br/><br/>
    <span style="width:60px;display:inline-block;">鹰币：</span>
    <input id="score" name="score" class="mini-textbox" required="true"  type="number" style="width:155px;" />
    <span style="width:60px;display:inline-block;">运费：</span>
    <input id="freight" name="freight" class="mini-textbox" required="true" type="number" style="width:155px;" />
    <br/><br/>
    <span style="width:60px;display:inline-block;">购买数量：</span>
    <input id="count" name="count" class="mini-textbox" required="true" type="number" style="width:155px;" />
    <span style="width:60px;display:inline-block;">赠送积分：</span>
    <input id="presentScore" name="presentScore" class="mini-textbox" required="true" type="number" style="width:155px;" />
    <br/><br/>
    <span style="width:60px;display:inline-block;">商城分类：</span>
    <input id="classify" name="classify" class="mini-combobox" required="true" type="text" style="width:155px;" data="tecShopType"/>
    <br/><br/>
    <span style="width:150px;display:inline-block;">上一级分成钱：</span>
    <input id="superiorMoney" name="superiorMoney" class="mini-textbox" type="number" style="width:155px;" value="0" />
    <br/><br/>
    <span style="width:150px;display:inline-block;">上二级分成钱：</span>
    <input id="superiorSuperiorMoney" name="superiorSuperiorMoney" class="mini-textbox" type="number" style="width:155px;" value="0" />
    <br/><br/>
    <span style="width:150px;display:inline-block;">上二级祖辈分成钱：</span>
    <input id="ancestorsMoney" name="ancestorsMoney" class="mini-textbox" type="number" style="width:155px;" value="0"/>
    <br/><br/>
    <span style="width:150px;display:inline-block;">上一级分成积分比例：</span>
    <input id="superiorScore" name="superiorScore" class="mini-textbox" type="number" style="width:155px;" value="0"/>
    <br/><br/>
    <span style="width:150px;display:inline-block;">上二级分成积分比例：</span>
    <input id="superiorSuperiorScore" name="superiorSuperiorScore" class="mini-textbox" type="number" style="width:155px;" value="0"/>
    <br/><br/>
    <span style="width:150px;display:inline-block;">上二级祖辈分成积分比例：</span>
    <input id="ancestorsScore" name="ancestorsScore" class="mini-textbox" type="number" style="width:155px;" value="0"/>
    <br/><br/>
</div>
<div style="margin: 30px 0;text-align: center">
    <a class="mini-button " iconCls="icon-ok" onclick="addTECGoodShop()">确定</a>
    <a class="mini-button" iconCls="icon-cancel" onclick="onCancel">取消</a>
</div>
</body>
<script>
  let tecShopType = JSON.parse('<%- result %>');
  function addTECGoodShop(){
    var form = new mini.Form("#form1");
    form.validate();
    if (form.isValid() == false) {
      alert("请正确填写数据")
      return
    };
    var shopGoodsOId = mini.get("btnEdit1").getValue();
    var price = mini.get("price").getValue();
    var score = mini.get("score").getValue();
    var freight = mini.get("freight").getValue();
    var count = mini.get("count").getValue();
    var classify = mini.get("classify").getText()
    var presentScore = mini.get("presentScore").getValue();
    var superiorMoney = mini.get("superiorMoney").getValue();
    var superiorSuperiorMoney = mini.get("superiorSuperiorMoney").getValue();
    var ancestorsMoney = mini.get("ancestorsMoney").getValue();
    var superiorScore = mini.get("superiorScore").getValue();
    var superiorSuperiorScore = mini.get("superiorSuperiorScore").getValue();
    var ancestorsScore = mini.get("ancestorsScore").getValue();
    // console.log(classify,"classify======")
    $.ajax({
      type: "POST",
      url: "/getdata/addTECShopGoods",
      data:{
        shopGoodsOId,
        price,
        score,
        freight,
        count,
        classify,
        presentScore,
        superiorMoney,
        superiorSuperiorMoney,
        ancestorsMoney,
        superiorScore,
        superiorSuperiorScore,
        ancestorsScore
      },

      success: function (result) {
        if(result =="1"){
          alert("保存成功");
          CloseWindow("save");
        }else{
          alert("保存失敗")
          CloseWindow("save");
        }

      }
    })
  }

  function CloseWindow(action) {
    if (action == "close" && form.isChanged()) {
      if (confirm("数据被修改了，是否先保存？")) {
        return false;
      }
    }
    if (window.CloseOwnerWindow) return window.CloseOwnerWindow(action);
    else window.close();
  }

  function onCancel(e) {
    CloseWindow("cancel");
  }

  function onButtonEdit(e) {
    var btnEdit = this;
    mini.open({
      url: "/editor/shopGoodsChoice",
      title: "商品列表",
      width: 1100,
      height: 450,
      ondestroy: function (action) {
        if (action == "ok") {
          var iframe = this.getIFrameEl();
          var data = iframe.contentWindow.GetData();
          data = mini.clone(data);    //必须
          if (data) {
            btnEdit.setText(data.text);
            btnEdit.setValue(data.id);
          }
        }else {
          btnEdit.setText("");
        }

      }
    });

  }
</script>
</html>